﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PS_NonWorkingJobSites.aspx.cs" Inherits="KPIS.GERP.GHRMS.APP.PS_NonWorkingJobSites" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">

</head>
<body class="BODY">
    <form runat="server" id="mainForm" method="post" style="width: 100%">
    <link href="../../Styles/CssClass.css" rel="stylesheet" type="text/css" />    
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">        
        <script type="text/javascript">
            var cancelDropDownClosing = false;            
            function StopPropagation(e)
            {
                //cancel bubbling
                e.cancelBubble = true;
                if (e.stopPropagation)
                {
                    e.stopPropagation();
                }
            }

            function onDropDownClosing()
            {
                cancelDropDownClosing = false;
            }

            function onCheckBoxClick(chk)
            { 
                var combo = $find("<%= cmbJobSite.ClientID %>");
                //var combo2 = $find("<%= RadComboBox2.ClientID %>");
                //prevent second combo from closing
                cancelDropDownClosing = true;
                //holds the text of all checked items
                var text = "";
                //holds the values of all checked items
                var values = "";
                //get the collection of all items
                var items = combo.get_items();
                //enumerate all items
                for (var i = 0; i < items.get_count(); i++)
                {
                    var item = items.getItem(i);
                    //get the checkbox element of the current item
                    var chk1 = $get(combo.get_id() + "_i" + i + "_chk1");
                    if (chk1.checked)
                    {
                        text += item.get_text() + "," ;
                        values += item.get_value() + ","; 
                    }
                }
                //remove the last comma from the string
                text = removeLastComma(text);
                values = removeLastComma(values);
             
                if (text.length > 0)
                {
                    //set the text of the combobox
                    combo.set_text(text);
                    //update the treeview in the second combobox 
                    updateTreeView(values);
                    //combo2.set_text("");
                    //open the second combobox
//                    if (!combo2.get_dropDownVisible())
//                        combo2.showDropDown();
                }
                else
                {
                    //all checkboxes are unchecked
                    //so reset the controls 
                    combo.set_text(""); 
                    updateTreeView(values); 
//                    combo2.set_emptyMessage("Showing all cars");
                }
            }

            //this method hides the nodes of the treeeview depending on 
            //the checked items in the first combobox
            function updateTreeView(values)
            {
                var arrValues = values.split(",");
//                var combo2 = $find("<%= RadComboBox2.ClientID %>");
//                var tree = combo2.get_items().getItem(0).findControl("RadTreeView1");
                var nodes = tree.get_allNodes(); 
             
                for (var i = 0; i < nodes.length; i++)
                {
                    var node = nodes[i];
                    //set all nodes visible initially
                    node.set_visible(true);
                    //hide all leaf nodes which value does not exist in the values string
                    if (values.indexOf(node.get_value()) == -1 && node.get_value() && values.length > 0)
                    {
                        node.set_visible(false);
                    }
                }
             
                //loop through loop nodes only and hide
                //the ones that does not have any visible child node
                //expand the others
                var rootNodes = tree.get_nodes();
                for (var i = 0; i < rootNodes.get_count(); i++)
                {
                    var root = rootNodes.getNode(i);
                    var showTheRootNode = false;
                    for (var j = 0; j < root.get_nodes().get_count(); j++)
                    {
                        if (root.get_nodes().getNode(j).get_visible())
                        {
                            root.expand();
                            showTheRootNode = true;
                            break;
                        } 
                    }
                    root.set_visible(showTheRootNode);
                }
            } 

            //this method removes the ending comma from a string
            function removeLastComma(str)
            {
                return str.replace(/,$/,"");
            }

            function OnClientNodeClickingHandler(sender, e)
            {
                var node = e.get_node();
                //check if we have clicked on a Make
                if (node.get_category() == "Make")
                {
                    node.toggle();
                }
                else
                {
                    //find the combobox, set its text and close it
                    var combo = $find("<%= RadComboBox2.ClientID %>"); 
                    combo.set_text(node.get_text());
                    cancelDropDownClosing = false;
                    combo.hideDropDown();
                }
            }

            function OnClientDropDownClosingHandler(sender, e)
            {
                //do not close the second combo if 
                //a checkbox from the first is clicked
                e.set_cancel(cancelDropDownClosing);
            }

            </script>        
    </telerik:RadCodeBlock>
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
        <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="Panel1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="Panel2">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="Panel2" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadTreeView1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" 
                        LoadingPanelID="RadAjaxLoadingPanel2" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" 
                        LoadingPanelID="" />
                </UpdatedControls>
            </telerik:AjaxSetting>            
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadTreeView1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <asp:Panel runat="server" ID="Panel1" Style="float: left; width: 373px; border-right: 1px solid #B1D8EB;">
            <div class="tree-title">
                รายชื่อหน่วยงาน&nbsp;
                <asp:Button ID="cmdAddItem" runat="server" Text="เพิ่มหน่วยงาน" Width="106px" 
                    onclick="cmdAddItem_Click" />
            </div>
            <div class="tree-panel">
                <telerik:RadTreeView 
                    ID="RadTreeView1" 
                    runat="server" 
                    CheckBoxes="True" 
                    DataFieldID="Id" 
                    DataFieldParentID="parent_id" 
                    DataTextField="Name" 
                    DataValueField="Id" 
                    Height="280px"
                    TriStateCheckBoxes="true" 
                    CheckChildNodes="true" onnodeclick="RadTreeView1_NodeClick" 
                    onnodeexpand="RadTreeView1_NodeExpand" >                    
                </telerik:RadTreeView>
                <br />
                <br />
                <br />
                <div >
                    <asp:Label ID="lblNwdSeq" runat="server" Visible ="false" /></div>
            </div>
        </asp:Panel>
        <asp:Panel runat="server" ID="Panel2" Style="width: 500px;float:left;" 
            Width="451px">
            <div class="tree-title">
                รายชื่อหน่วยงานที่หยุด
                <asp:Label ID="lblNwdDate" runat="server" BorderStyle="None" CssClass="text" />
            </div>
            <div class="tree-panel">
                <telerik:RadGrid ID="RadGrid1" 
                    runat="server" 
                    AllowAutomaticDeletes="True" 
                    AllowFilteringByColumn="True" 
                    AllowMultiRowEdit="True" 
                    AllowMultiRowSelection="True" 
                    AllowPaging="True" 
                    AllowSorting="True" 
                    AutoGenerateColumns="False" 
                    EnableAJAX="True" 
                    EnableAJAXLoadingTemplate="True" 
                    GridLines="None" 
                    OnItemCommand="RadGrid1_ItemCommand" Skin="Outlook" 
                    Width="450px">
                    <MasterTableView 
                        AllowMultiColumnSorting="True" 
                        CellSpacing="-1" 
                        ClientDataKeyNames="Seq" 
                        CommandItemDisplay="Top" 
                        DataKeyNames="Seq" 
                        InsertItemPageIndexAction="ShowItemOnCurrentPage" 
                        NoMasterRecordsText="&lt; ไม่มีข้อมูล &gt;">
                        <CommandItemTemplate>
                            <table width="100%">
                                <tr>
                                </tr>
                            </table>
                        </CommandItemTemplate>
                        <RowIndicatorColumn>
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn>
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" ItemStyle-Width="15" EditText = "คลิกเพื่อแก้ไขรายการ">
                                <ItemStyle Width="15px" HorizontalAlign ="Center" />
                            </telerik:GridEditCommandColumn>
                            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" 
                                ConfirmDialogType="RadWindow" ConfirmText="ลบข้อมูลที่เลือก?" 
                                ItemStyle-Width="15" Text="คลิกเพื่อลบรายการ" UniqueName="column1">
                                <ItemStyle Width="15px" HorizontalAlign ="Center" />
                            </telerik:GridButtonColumn>
                            <telerik:GridBoundColumn DataField="Seq" DataType="System.Int32" 
                                Display="False" HeaderText="Seq" ReadOnly="True" 
                                UniqueName="Seq" Visible="False">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn AutoPostBackOnFilter="true" 
                                DataField="JobSiteName" FilterControlWidth="100%" 
                                HeaderStyle-HorizontalAlign="Center" HeaderText="หน่วยงาน" 
                                ShowFilterIcon="false" UniqueName="JobSiteName">
                                <HeaderStyle HorizontalAlign="Center" Width="200px" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="Remarks" 
                                FilterControlWidth="100%" HeaderStyle-HorizontalAlign="Center" 
                                HeaderText="หมายเหตุ" ShowFilterIcon="false" UniqueName="Remarks">
                                <HeaderStyle HorizontalAlign="Center" Width="100px" />
                            </telerik:GridBoundColumn>
                        </Columns>
                        <EditFormSettings EditFormType="WebUserControl" 
                            UserControlName="../UserControls/PS_NonWorkingJobSites.ascx">
                            <EditColumn UniqueName="EditCommandColumn1">
                            </EditColumn>
                        </EditFormSettings>
                        <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                    </MasterTableView>
                    <ClientSettings AllowColumnHide="True" AllowColumnsReorder="True" 
                        EnableRowHoverStyle="True" ReorderColumnsOnClient="True">
                        <Selecting AllowRowSelect="True" EnableDragToSelectRows="true" />
                    </ClientSettings>
                </telerik:RadGrid>
            </div>
        </asp:Panel>
        <div style="clear: both">
        </div>
        <!-- content end -->
    </form>
</body>
</html>

